package com.homedo.microservice.open.service.gateway.util;

import com.google.common.collect.Lists;

import java.util.List;

public class ThreadUtil {

    public static List<Thread> getThreadByName(String name) {
        List<Thread> threads = Lists.newArrayList();

        ThreadGroup currentGroup =
                Thread.currentThread().getThreadGroup();
        int noThreads = currentGroup.activeCount();
        Thread[] lstThreads = new Thread[noThreads];
        currentGroup.enumerate(lstThreads);

        for (int i = 0; i < noThreads; i++) {
            if (name.equals(lstThreads[i].getName())) {
                threads.add(lstThreads[i]);
            }
            System.out.println("线程号：" + i + " = " + lstThreads[i].getName());
        }

        return threads;
    }
}
